#include <REGX52.H>
#include "Delay.h"
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLCD=P1^5;


void MatrixLED_ShowColumn(unsigned char row,unsigned char colData)
{
    if (row > 7)
    {
        row = 7;
    }
    P1 &= 0xE0;
    P1 |= row;
    P0=~colData;
}

void MatrixLED_Enable(unsigned char en)
{
    ENLCD=en;
}

void MatrixLED_ShowPage(unsigned char Page_Buffer_1[])
{
    unsigned char i;
    if(Page_Buffer_1)
    {
        for(i=0;i<=7;i++)
        {
            MatrixLED_ShowColumn(i,0x00);
            MatrixLED_ShowColumn(i, Page_Buffer_1[i]);
            MatrixLED_ShowColumn(i, 0x00);
        }
        
    }
}

// 使用静态变量保持状态
void MatrixLED_Left(unsigned char Page_Buffer_2[])
{
    static unsigned char Offset = 0;
    static unsigned char Count = 0;
    unsigned char i;

    // 显示当前偏移后的内容
    for (i = 0; i < 8; i++)
    {
        // 计算源列索引，使用模运算防止越界
        unsigned char src_col = (i + Offset) % 8;
        MatrixLED_ShowColumn(i, Page_Buffer_2[src_col]);
    }

    // 更新计数器和偏移量
    Count++;
    if (Count >250) // 每11次调用移动一次
    {
        Count = 0;
        Offset = (Offset + 1) % 8; // 循环偏移
    }
}
